﻿<?php
class EditActionController extends ActionController {

    public function run() {
        
        //if(isset($this->params['newArt'])) {
        $articleMapper = ArticleMapper::instance();
        //разделить функцию
        $editArt = $articleMapper->getArticles('id', $this->params['artID']);
        //???
        if($editArt->isOwner($this->user->id){}
        
        
        if($this->isPost()) {
            

            $article = new Article($this->getPost());
            $articleMapper->editArticle($article);
            
            if($articleMapper->hasErrors()){
                $this->view->errors = $articleMapper->getErrors();
                // $article
                //.......
            }
            
            //$articleMapper->editArticle($this->params['artID'],$this->params['newSubj'], $this->params['newTags'],$this->params['newArt']);
            $this->redirect('index');
            $this->redirectURL('/index/asd asd asd ');
            $arts = $articleMapper->getArticles();
            
            $userMapper = UserMapper::instance();
            $userMapper->getFullUserName($arts);
            $commentMapper = CommentMapper::instance();
            $commentMapper->getCountCommentsForArticles($arts);            
            
            $this->view->articles = $arts;
        
            $this->view->user = $this->user;
            
            $this->view->setRenderTemplate('index.phtml');            
        } else { 
            $this->view->editArt = $editArt[0];
            $this->view->setRenderTemplate('edit.phtml');
        }
    }
}

?>